src/reverse.js
thoward37@gmail.com/shirt[create-new-file-src-reverse-js-exports] / src / reverse.js
@ c048e7fd
Download
/**
* Reverses the characters of a string.
*
* @param {string} s - The string to reverse.
* @returns {string} The reversed string.
* @throws {TypeError} If the input is not a string.
*/
export function reverse(s) {
if (typeof s !== "string") {
throw new TypeError("Input must be a string");
}
// An empty string will naturally return an empty string.
return s.split("").reverse().join("");
}